﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true"
    CodeFile="CategoryItem.aspx.cs" Inherits="Admin_CategoryItem" %>

<asp:Content ID="Content1" ContentPlaceHolderID="Main_HeaderContentPlaceHolder" runat="Server">
    <script type="text/javascript">
        function Mandatory(sender, e) {
            e.IsValid = (e.Value != '0');
        }
    </script>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="Main_MainContentPlaceHolder" runat="Server">
    <div>
        <asp:MultiView ID="MultiView" runat="server" ActiveViewIndex="0">
            <asp:View ID="ShowView" runat="server">
                <div id="maincontainer">
                    <div id="topsection">
                        <div class="innertube">
                            <asp:Label ID="Label1" runat="server" SkinID="Lable100" Text="عنوان گروه:"></asp:Label>
                            <asp:TextBox ID="CategoryTextBox" runat="server" SkinID="TextBox200"></asp:TextBox>
                            <asp:Label ID="Label2" runat="server" SkinID="Lable100" Text="اندازه صفحه:"></asp:Label>
                            <asp:DropDownList ID="PageSizeDropDownList" runat="server" SkinID="DropDownList198">
                                <asp:ListItem Selected="True" Value="5">[پیش فرض]</asp:ListItem>
                                <asp:ListItem Value="5">5 رکورد</asp:ListItem>
                                <asp:ListItem Value="10">10 رکورد</asp:ListItem>
                                <asp:ListItem Value="15">15 رکورد</asp:ListItem>
                                <asp:ListItem Value="20">20 رکورد</asp:ListItem>
                                <asp:ListItem Value="25">25 رکورد</asp:ListItem>
                                <asp:ListItem Value="1000000">تمام رکورد ها</asp:ListItem>
                            </asp:DropDownList>
                            <asp:ImageButton ID="SearchImageButton" runat="server" OnClick="SearchImageButton_Click"
                                SkinID="SearchButton" />
                            <asp:ImageButton ID="ClearImageButton" runat="server" OnClick="ClearImageButton_Click"
                                OnClientClick="return false;" SkinID="ClearButton" />
                        </div>
                    </div>
                    <div id="contentwrapper">
                            <div class="innertube">
                                <asp:GridView ID="CategoryGridView" runat="server" AllowPaging="True" AutoGenerateColumns="False"
                                    DataKeyNames="CategoryID" DataSourceID="CategoryEntityDataSource" HorizontalAlign="Center"
                                    OnSelectedIndexChanged="CategoryGridView_SelectedIndexChanged" Width="100%" PageSize="5">
                                    <Columns>
                                        <asp:BoundField DataField="CategoryID" HeaderText="CategoryID" ReadOnly="True" Visible="false"
                                            SortExpression="CategoryID" />
                                        <asp:TemplateField>
                                            <ItemTemplate>
                                                <asp:ImageButton ID="SelectImageButton" runat="server" CommandName="Select" SkinID="SelectButton" />
                                            </ItemTemplate>
                                            <ItemStyle Width="25px" />
                                        </asp:TemplateField>
                                        <asp:BoundField DataField="CategoryTitle" HeaderText="عنوان گروه" ReadOnly="True"
                                            SortExpression="CategoryTitle">
                                            <ItemStyle Width="300px" />
                                        </asp:BoundField>
                                        <asp:BoundField DataField="Description" HeaderText="توضیحات" ReadOnly="True" SortExpression="Description">
                                            <ItemStyle Width="450px" />
                                        </asp:BoundField>
                                    </Columns>
                                </asp:GridView>
                            </div>
                    </div>
            </asp:View>
            <asp:View ID="EditView" runat="server">
                <table>
                    <tr style="color: #FFFFFF">
                        <td style="width: 450px">
                            عنوان گروه آزمایش:
                            <asp:Label ID="CategoryLabel" runat="server" Text=""></asp:Label>
                        </td>
                        <td>
                        </td>
                        <td style="text-align: center; width: 350px">
                            <asp:LinkButton ID="ReturnLinkButton" runat="server" OnClick="ReturnLinkButton_Click">بازگشت</asp:LinkButton>
                        </td>
                    </tr>
                    <tr>
                        <td valign="top" style="width: 450px">
                            <asp:GridView ID="CategoryItemGridView" runat="server" AllowPaging="True" AutoGenerateColumns="False"
                                DataKeyNames="CategoryItemID" DataSourceID="CategoryItemEntityDataSource" HorizontalAlign="Center"
                                OnSelectedIndexChanged="CategoryItemGridView_SelectedIndexChanged" Width="100%"
                                AllowSorting="True" PageSize="5">
                                <Columns>
                                    <asp:TemplateField>
                                        <ItemTemplate>
                                            <asp:ImageButton ID="SelectImageButton" runat="server" CommandName="Select" SkinID="SelectButton" />
                                        </ItemTemplate>
                                        <ItemStyle Width="25px" />
                                    </asp:TemplateField>
                                    <asp:BoundField DataField="CategoryItemID" HeaderText="CategoryItemID" ReadOnly="True"
                                        SortExpression="CategoryItemID" Visible="false" />
                                    <asp:BoundField DataField="CategoryItemTitle" HeaderText="عنوان آزمایش" SortExpression="CategoryItemTitle" />
                                    <asp:BoundField DataField="Description" HeaderText="توضیحات" SortExpression="Description" />
                                </Columns>
                            </asp:GridView>
                        </td>
                        <td style="width: 20px">
                        </td>
                        <td style="width: 350px" valign="top">
                            <asp:FormView ID="CategoryItemFormView" runat="server" DataSourceID="CategoryItemEntityDataSource"
                                DataKeyNames="CategoryItemID" DefaultMode="Insert" OnItemCommand="CategoryItemFormView_ItemCommand"
                                Width="100%">
                                <EditItemTemplate>
                                       <table border="0" cellpadding="0" cellspacing="0" style="width: 350px">
                                        <tr valign="middle">
                                            <td style="width: 100px" align="right">
                                                عنوان آزمایش:
                                            </td>
                                            <td style="width: 250px" align="right">
                                                <asp:TextBox ID="TitleTextBox" runat="server" Text='<%# Bind("CategoryItemTitle") %>'
                                                    MaxLength="500" Width="250px" />
                                                <asp:RequiredFieldValidator ID="TitleRequiredFieldValidator" runat="server" ControlToValidate="TitleTextBox"
                                                    Display="Dynamic" ErrorMessage="*" ValidationGroup="Update"></asp:RequiredFieldValidator>
                                                <asp:HiddenField ID="CategoryIDHiddenField" runat="server" Value='<%# Bind("CategoryID") %>' />
                                            </td>
                                        </tr>
                                        <tr valign="middle">
                                            <td style="width: 100px" align="right">
                                                توضیحات:
                                            </td>
                                            <td align="right" dir="rtl">
                                                <asp:TextBox ID="DescriptionTextBox" runat="server" Text='<%# Bind("Description") %>'
                                                    TextMode="MultiLine" MaxLength="2500" Height="150px" Width="250px" />
                                            </td>
                                        </tr>
                                        <tr>
                                            <td colspan="2" align="left">
                                                <table border="0" cellpadding="0" cellspacing="0" style="width: 100%">
                                                    <tr>
                                                        <td style="height: 15px">
                                                            &nbsp;
                                                        </td>
                                                        <td align="left" valign="top" style="width: 65px">
                                                            <asp:ImageButton ID="DeleteImageButton" runat="server" CausesValidation="False" CommandName="Delete"
                                                                SkinID="DeleteButton" OnClientClick="if (!confirm('آيا از حذف مطمئن هستيد؟')) return false;" />
                                                        </td>
                                                        <td align="left" valign="top" style="width: 65px">
                                                            <asp:ImageButton ID="UpdateImageButton" runat="server" CommandName="Update" SkinID="UpdateButton"
                                                                ValidationGroup="Update" OnClientClick="if (!confirm('آيا از اعمال تغییرات مطمئن هستيد؟')) return false;" />
                                                        </td>
                                                        <td align="left" valign="top" style="width: 65px">
                                                            <asp:ImageButton ID="CancelImageButton" runat="server" CommandName="Cancel" SkinID="CancelButton" />
                                                        </td>
                                                    </tr>
                                                </table>
                                            </td>
                                        </tr>
                                    </table>
                                </EditItemTemplate>
                                <InsertItemTemplate>
                                    <table border="0" cellpadding="0" cellspacing="0" style="width: 350px">
                                        <tr valign="middle">
                                            <td style="width: 100px" align="right">
                                                عنوان آزمایش:
                                            </td>
                                            <td style="width: 250px" align="right">
                                                <asp:TextBox ID="TitleTextBox" runat="server" Text='<%# Bind("CategoryItemTitle") %>'
                                                    MaxLength="500" Width="250px" />
                                                <asp:RequiredFieldValidator ID="TitleRequiredFieldValidator" runat="server" ControlToValidate="TitleTextBox"
                                                    Display="Dynamic" ErrorMessage="*" ValidationGroup="Insert"></asp:RequiredFieldValidator>
                                                <asp:HiddenField ID="CategoryIDHiddenField" runat="server" Value='<%# Bind("CategoryID") %>' />
                                            </td>
                                        </tr>
                                        <tr valign="middle">
                                            <td style="width: 100px" align="right">
                                                توضیحات:
                                            </td>
                                            <td align="right" dir="rtl">
                                                <asp:TextBox ID="DescriptionTextBox" runat="server" Text='<%# Bind("Description") %>'
                                                    TextMode="MultiLine" MaxLength="2500" Height="150px" Width="250px" />
                                            </td>
                                        </tr>
                                        <tr>
                                            <td colspan="2" align="left">
                                                <table border="0" cellpadding="0" cellspacing="0" style="width: 100%">                                                 
                                                    <tr>
                                                        <td style="height: 15px">
                                                            &nbsp;
                                                        </td>
                                                        <td align="left" valign="top" style="width: 65px;">
                                                            <asp:ImageButton ID="InsertButton" runat="server" CommandName="Insert" SkinID="InsertButton"
                                                                ValidationGroup="Insert" OnClick="InsertButton_Click" />
                                                        </td>
                                                        <td align="left" valign="top" style="width: 65px;">
                                                            <asp:ImageButton ID="CancelButton" runat="server" CausesValidation="False" CommandName="Cancel"
                                                                SkinID="CancelButton" />
                                                        </td>
                                                    </tr>
                                                </table>
                                            </td>
                                        </tr>
                                    </table>
                                </InsertItemTemplate>
                            </asp:FormView>
                        </td>
                    </tr>
                </table>
            </asp:View>
        </asp:MultiView>
        <asp:HiddenField ID="CategoryIDHiddenField" runat="server" />
        <asp:EntityDataSource ID="CategoryEntityDataSource" runat="server" ConnectionString="name=DataEntities"
            DefaultContainerName="DataEntities" OrderBy="it.[CategoryTitle]" EntitySetName="Categories"
            Select="it.[CategoryID], it.[CategoryTitle], it.[Description]" Where="(@CategoryTitle is null || it.CategoryTitle LIKE '%' + @CategoryTitle + '%')"
            EnableFlattening="False">
            <WhereParameters>
                <asp:ControlParameter ControlID="CategoryTextBox" Name="CategoryTitle" Type="String" />
            </WhereParameters>
        </asp:EntityDataSource>
        <asp:EntityDataSource ID="CategoryItemEntityDataSource" runat="server" ConnectionString="name=DataEntities"
            DefaultContainerName="DataEntities" EnableDelete="True" EnableInsert="True" EnableUpdate="True"
            EntitySetName="CategoryItems" OnDeleted="CategoryItemEntityDataSource_Command"
            OnInserted="CategoryItemEntityDataSource_Command" OnUpdated="CategoryItemEntityDataSource_Command"
            Where="it.Category.CategoryID = @CategoryID" Include="Category" EnableFlattening="False">
            <WhereParameters>
                <asp:ControlParameter ControlID="CategoryIDHiddenField" DbType="Int32" Name="CategoryID"
                    PropertyName="Value" DefaultValue="0" />
            </WhereParameters>
        </asp:EntityDataSource>
    </div>
</asp:Content>
